home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / SATminimal demo ƒ / sMySprite.c < prev    next >
C/C++ Source or Header  |  1994-08-22  |  1KB  |  51 lines

  1. #include "SAT.h"
  2.  
  3.     Handle    theSound;
  4.     FacePtr    faces[6];
  5.  
  6. /* Prototypes */
  7.  void InitMySprite();
  8.  pascal void SetupMySprite (SpritePtr);
  9.  pascal void HandleMySprite (SpritePtr);
  10.  
  11.  
  12. void InitMySprite()
  13. {
  14. int i;
  15.  
  16.     theSound = SATGetSound(128);    /*Preload the sound */
  17.     for (i=0; i<=5; i++)
  18.         faces[i] = SATGetFace(128+i);    /* Preload all sprite faces */
  19. }
  20.  
  21. /* Important! Callback routines (Setup, Handle, Hit) must be declared "pascal"! */
  22.  
  23. pascal void SetupMySprite (me)
  24. SpritePtr me;
  25. {
  26.     me->mode = 0;                    /* Pick a valid face number */
  27.     me->speed.h = 2;                /* Set the speed - only horizontal is used here */
  28.     me->task = HandleMySprite;        /* Set a handling routine. MANDATORY! If nil, the sprite will self-destruct. */
  29. }
  30.  
  31. pascal void HandleMySprite (me)
  32. SpritePtr me;
  33. {
  34. /* Choose face */
  35.     me->mode = (me->mode + 1) % 6;
  36.     me->face = faces[me->mode];
  37.  
  38. /* Move */
  39.     me->position.h = me->position.h + me->speed.h;
  40.     if (me->position.h > gSAT.offSizeH - 16)
  41.         {
  42.             me->speed.h = -2;
  43.             SATSoundPlay(theSound, 1, false);
  44.         };
  45.     if (me->position.h < -16)
  46.         {
  47.             me->speed.h = 2;
  48.             SATSoundPlay(theSound, 1, false);
  49.         };
  50. }
  51.